import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

# http://docs.python.org/2/library/email-examples.html

# from email.MIMEMultipart import MIMEMultipart
# from email.MIMEText import MIMEText
# from email.MIMEImage import MIMEImage

msg = MIMEMultipart()
print msg

gmail_user = 'yuwei.mu@gmail.com'
gmail_pwd = '!Abcd12#$'

mail_to = 'moogates@gmail.com'

msg['Subject'] = "jztzp click statistics"
msg['From'] = gmail_user
msg['To'] = mail_to
msg['Cc'] = gmail_user

fp = open("./email_with_attachment.py", 'r')
mime_txt = MIMEText(fp.read())
fp.close()
msg.attach(mime_txt)

smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_pwd)
print "Sending file to" + mail_to
smtpserver.sendmail(gmail_user, mail_to, msg.as_string())
print 'done!'
smtpserver.close()

